<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h4>视频地址</h4>
    https://www.bilibili.com/video/BV1rA4y1f7mM/?
</body>
<script>
    // for while循环性能差不多
    let arr = new Array(99999).fill(0);
    console.time("For~")
    // 使用let声明的变量要比var声明的变量执行速度要快
    for (let index = 0; index < arr.length; index++) { }
    console.timeEnd("For~")

    console.time("while~")
    let i = 0;
    while (i < arr.length) {
        i++;
    }
    console.timeEnd("while~")

    // forEach执行速度要比for while慢
    console.time("forEach~")
    arr.forEach(function () { })
    console.timeEnd("forEach~")

    // for in 性能很差 迭代当前对象中所有可枚举的属性的
    console.time("for in~")
    for (const key in arr) {
    }
    console.timeEnd("for in~")

    // for of 循环的原理是按照迭代器规范遍历的
    console.time("for of~")
    for (const val of arr) { }
    console.timeEnd("for of~")

</script>

</html>